package com.sunchangming.stmdb.helper;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Map;

public class NameDirectorySer2 implements Serializer {

	@SuppressWarnings("unchecked")
	@Override
	public byte[] serialize(Object obj) throws IOException {
		final Map<String, Long> data = (Map<String, Long>) obj;
		final ByteArrayOutputStream baos = new ByteArrayOutputStream();
		final DataOutputStream oos = new DataOutputStream(baos);
		oos.write(data.size());
		for (final Map.Entry<String, Long> e : data.entrySet()) {
			oos.writeUTF(e.getKey());
			oos.writeLong(e.getValue());
		}

		oos.flush();
		return baos.toByteArray();
	}

	@Override
	public Object deserialize(byte[] serialized) throws IOException {
		return null;
	}

}
